<?php

namespace app\admin\controller\user;

use app\common\controller\Backend;

/**
 * 会员管理
 *
 * @icon fa fa-circle-o
 */
class User extends Backend
{
    
    /**
     * User模型对象
     * @var \app\admin\model\user\User
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\user\User;
        $this->view->assign("sexList", $this->model->getSexList());
        $this->view->assign("islookList", $this->model->getIslookList());
        $this->view->assign("approveStatusList", $this->model->getApproveStatusList());
    }

    public function del($ids = "")
    {
        if ($ids) {
            $pk = $this->model->getPk();
            $adminIds = $this->getDataLimitAdminIds();
            if (is_array($adminIds)) {
                $count = $this->model->where($this->dataLimitField, 'in', $adminIds);
            }
            $list = $this->model->where($pk, 'in', $ids)->select();
            $count = 0;
            foreach ($list as $k => $v) {
                $this->delRelevance($v['id']);
                $count += $v->delete();
            }
            if ($count) {
                $this->success();
            } else {
                $this->error(__('No rows were deleted'));
            }
        }
        $this->error(__('Parameter %s can not be empty', 'ids'));
    }

    public function delRelevance($uid = null)
    {
        $bbsReplyModel          = new \app\admin\model\bbs\Reply;
        $bbsReplyzanModel       = new \app\admin\model\bbs\Replyzan;
        $bbsReportModel         = new \app\admin\model\bbs\Report;
        $bbsContentsModel       = new \app\admin\model\bbs\Contents;

        $bbsReplyModel->where('user_id', $uid)->delete();
        $bbsReplyzanModel->where('user_id|bbsreply_id', $uid)->delete();
        $bbsReportModel->where('user_id', $uid)->delete();
        $bbsContentsModel->where('user_id', $uid)->delete();

        $attentionSuzerainModel = new \app\admin\model\user\attention\Suzerain;
        $attentionBbsModel      = new \app\admin\model\user\attention\Bbsmodel;
        $digitalslidesModel     = new \app\admin\model\user\Digitalslides;
        $articleModel           = new \app\admin\model\user\Article;
        $approveModel           = new \app\admin\model\user\Approve;
        $thirdModel             = new \addons\third\model\Third;

        $attentionSuzerainModel->where('user_id|other_id', $uid)->delete();
        $attentionBbsModel->where('user_id', $uid)->delete();
        $digitalslidesModel->where('user_id', $uid)->delete();
        $articleModel->where('user_id', $uid)->delete();
        $approveModel->where('user_id', $uid)->delete();
        $thirdModel->where('user_id', $uid)->delete();
    }

}
